#include "Common.hpp"
#include "Physics/PhysWorld.hpp"
#include "Math/Vector.hpp"
#include "Utility/InterfaceConversion.hpp"

#include "Box2D/Dynamics/b2Body.h"
#include "Box2D/Dynamics/b2World.h"

namespace Physics
{
	PhysWorld::PhysWorld( void )
		: world( new b2World( Utility::Box2DVector( Math::Vectorf( 0.0f, 0.0f ) ), true ) )
	{
	}

	PhysWorld::~PhysWorld( void )
	{
		delete world;
	}

	void PhysWorld::Step( const float interval, const int iterations )
	{
		world->Step( interval, iterations, iterations );
	}

	Math::Vectorf PhysWorld::GetGravity( void ) const
	{
		return Utility::CaffVector( world->GetGravity() );
	}

	void PhysWorld::SetGravity( Math::Vectorf &grav )
	{
		world->SetGravity( Utility::Box2DVector( grav ) );
	}

	b2Body *PhysWorld::CreateInternalBody( b2BodyDef *def )
	{
		return world->CreateBody( def );
	}

	void PhysWorld::RemoveInternalBody( b2Body *body )
	{
		world->DestroyBody( body );
	}
}